
package com.scs.application.modules.base.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.scs.application.consts.GlobalConsts;
import com.scs.application.consts.RoleConsts;
import com.scs.application.consts.SerialRuleConsts;
import com.scs.application.core.exceptions.BusinessException;
import com.scs.application.core.global.GlobalParamService;
import com.scs.application.core.serial.SerialUtils;
import com.scs.application.core.service.BaseServiceImpl;
import com.scs.application.core.utils.*;
import com.scs.application.enums.CertBusType;
import com.scs.application.enums.MaterialBidStatus;
import com.scs.application.enums.MaterialInquiryStatus;
import com.scs.application.modules.base.dto.InquiryDTO;
import com.scs.application.modules.base.dto.WinBiddingResultDTO;
import com.scs.application.modules.base.entity.*;
import com.scs.application.modules.base.mapper.MaterialInquiryMapper;
import com.scs.application.modules.base.request.MaterialBidItemQueryRequest;
import com.scs.application.modules.base.request.MaterialInquiryQueryRequest;
import com.scs.application.modules.base.service.*;
import com.scs.application.modules.base.vo.MaterialBidVO;
import com.scs.application.modules.doc.entity.FileInfo;
import com.scs.application.modules.doc.service.FileInfoService;
import com.scs.application.modules.upms.entity.Office;
import com.scs.application.modules.upms.entity.User;
import com.scs.application.modules.upms.service.OfficeService;
import com.scs.application.modules.upms.service.UserService;
import com.scs.application.modules.upms.vo.UserVO;
import com.google.common.collect.Lists;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.Serializable;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;

/**
 * 耗材询价单 service 实现
 */
@Slf4j
@AllArgsConstructor
@Service
@Transactional(rollbackFor = Exception.class)
public class MaterialInquiryServiceImpl extends BaseServiceImpl<MaterialInquiryMapper, MaterialInquiry> implements MaterialInquiryService {

    private final SupplierService supplierService;

    private final OfficeService officeService;

    private final UserService userService;

    private final MaterialInquiryItemService materialInquiryItemService;

    private final MaterialBidService materialBidService;

    private final MaterialBidItemService materialBidItemService;

    private final MaterialBidCertService materialBidCertService;

    private final HospitalSupplierService hospitalSupplierService;

    private final ManufacturerService manufacturerService;

    private final MaterialService materialService;

    private final MaterialSpecService materialSpecService;

    private final HospitalMaterialService hospitalMaterialService;

    private final FileInfoService fileInfoService;


    @Override
    public boolean removeCascadeById(Serializable id) {
        return super.removeById(id);
    }

    @Override
    public List<MaterialInquiry> list(MaterialInquiryQueryRequest request) {
        List<MaterialInquiry> list = this.list(getQueryWrapper(request));
        return list;
    }

    @Override
    public IPage<MaterialInquiry> page(MaterialInquiryQueryRequest request) {
        IPage page = this.page(request.getPage(), getQueryWrapper(request));
        return page;
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public void receiveInquiry(InquiryDTO dto) {
        String hospitalId = UserUtils.getHospitalId();
        /** 不允许重复推送 */
        List<MaterialInquiry> list = this.list(Wrappers.<MaterialInquiry>query()
                .eq("ref_id", dto.getRefId())
                .eq("hospital_id", hospitalId));
        if (!list.isEmpty()) {
            throw new BusinessException("询价单已在公网平台存在，不允许重复推送");
        }

        Map<String, List<InquiryDTO.SupplierDTO>> supplierItems = dto.getSupplierItems().stream()
                .collect(Collectors.groupingBy(InquiryDTO.SupplierDTO::getName));
        List<Supplier> supplierList = Lists.newArrayListWithCapacity(supplierItems.size());

        /** 处理供应商信息 */
        saveSupplier(supplierItems, supplierList);

        /** 保存询价单 */
        MaterialInquiry materialInquiry = new MaterialInquiry();
        BeanUtils.copyProperties(dto, materialInquiry);
        materialInquiry.setHospitalId(hospitalId)
                .setHospitalName(UserUtils.getHospital().getName());
        this.save(materialInquiry);

        /** 保存询价明细 */
        List<InquiryDTO.InquiryItemDTO> inquiryItems = dto.getInquiryItems();
        List<MaterialInquiryItem> inquiryItemList = Lists.newArrayListWithCapacity(inquiryItems.size());
        BeanUtils.copyProperties(inquiryItems, inquiryItemList, MaterialInquiryItem.class);
        inquiryItemList.stream().forEach(o -> {
            o.setInquiryId(materialInquiry.getId());
            o.setCatalogId("0");
            if (o.getSkuPriceMax() == null) {
                o.setSkuPriceMax(0.0);
            }
            if (o.getSkuPriceMin() == null) {
                o.setSkuPriceMin(0.0);
            }
        });
        materialInquiryItemService.saveBatch(inquiryItemList);

        /** 处理报价信息 */
        saveBid(supplierList, materialInquiry, inquiryItems, inquiryItemList);
    }


    @Transactional(rollbackFor = Exception.class)
    @Override
    public void endBidResultByRefId(String refId) {
        List<MaterialInquiry> miList = this.baseMapper.selectList(
                Wrappers.<MaterialInquiry>query()
                        .eq("hospital_id", UserUtils.getHospitalId())
                        .eq(StringUtils.isNotBlank(refId), "ref_id", refId)
        );
        if (miList.isEmpty()) {
            return;
        }
        for (MaterialInquiry mi : miList) {
            MaterialInquiry m = new MaterialInquiry();
            m.setFlowStatus(MaterialInquiryStatus.FINISHED.getValue()).setId(mi.getId());
            this.updateById(m);
        }
    }

    @Override
    public List<MaterialBidVO> findBidResultByRefId(String refId) {

        MaterialInquiry inquiry = this.getOne(Wrappers.<MaterialInquiry>query()
                .eq("hospital_id", UserUtils.getHospitalId())
                .eq("ref_id", refId)
        );

        if (inquiry == null) {
            throw new BusinessException("询价单不存在，请检查");
        }

        List<MaterialBid> bidList = materialBidService.list(Wrappers.<MaterialBid>query()
                .eq("flow_status", MaterialBidStatus.SUBMITTED.getValue())
                .eq("inquiry_id", inquiry.getId()));

        /** 响应数据 */
        List<MaterialBidVO> result = Lists.newArrayListWithCapacity(bidList.size());
        for (MaterialBid bid : bidList) {
            MaterialBidVO vo = new MaterialBidVO();
            vo.setSupplierId(bid.getSupplierId())
                    .setSupplierCode(bid.getSupplierCode())
                    .setSupplierName(bid.getSupplierName());

            /** 报价明细 */
            List<MaterialBidItem> bidItems = materialBidItemService.listVO(new MaterialBidItemQueryRequest().setBidId(bid.getId()));
            List<MaterialBidVO.ItemVO> itemVOS = Lists.newArrayListWithCapacity(bidItems.size());

            for (MaterialBidItem bidItem : bidItems) {
                MaterialBidVO.ItemVO itemVO = new MaterialBidVO.ItemVO();
                itemVO.setMaterialName(bidItem.getMaterialName())
                        .setMaterialSpec(bidItem.getMaterialSpec())
                        .setSkuPriceBid(bidItem.getSkuPriceBid())
                        .setRefId(bidItem.getRefId())
                        // todo 提交时间
                        .setBidDate(bid.getGmtModified())
                        .setBidRemark(bidItem.getBidRemark())
                        .setBidStatus(bidItem.getBiddingStrategies());
                itemVOS.add(itemVO);
            }

            /** 资质明细 */
            List<MaterialBidCert> certList = materialBidCertService.list(Wrappers.<MaterialBidCert>query()
                    .eq("bid_id", bid.getId()));
            List<MaterialBidVO.CertVO> certVOS = Lists.newArrayListWithCapacity(certList.size());

            String domain = GlobalParamService.getInstance().getDomain();

            // HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();

            // String url = request.getScheme() + "://" + request.getServerName() + ":" + request.getRemotePort();
            String url = "http://" + domain + "/";
            for (MaterialBidCert cert : certList) {
                MaterialBidVO.CertVO certVO = new MaterialBidVO.CertVO();
                String docIds = cert.getDocIds().stream().map((o -> o.toString())).collect(Collectors.joining(","));
                List<String> certUrls = cert.getDocIds().stream().map(o -> url + "/doc/files/" + o).collect(Collectors.toList());

                //增加扩展类型
                List<FileInfo> fileInfoS = fileInfoService.list(new QueryWrapper<FileInfo>().in("id", docIds));
                List<String> docExtTypes = Lists.newArrayListWithCapacity(certUrls.size());

                //默认jpg
                String defaultExtType = "jpg";

                for (String docId : docIds.split(",")) {
                    Optional<FileInfo> optFileInfoDTO = fileInfoS.stream().filter(o -> o.getId().equals(docId)).findFirst();
                    if (optFileInfoDTO.isPresent()) {
                        docExtTypes.add(optFileInfoDTO.get().getExtensionType());
                    } else {
                        docExtTypes.add(defaultExtType);
                    }
                }

                certVO.setCertName(cert.getCertName())
                        .setCertType(CertBusType.of(cert.getCertType()).getName())
                        .setCertificateNo(cert.getCertificateNo())
                        .setExpiryStartDate(cert.getExpiryStartDate())
                        .setExpiryEndDate(cert.getExpiryEndDate())
                        .setExtensionTypes(docExtTypes.toArray(new String[docExtTypes.size()]))
                        .setCertUrls(certUrls.toArray(new String[certUrls.size()]));
                certVOS.add(certVO);
            }

            vo.setItems(itemVOS).setCerts(certVOS);
            result.add(vo);
        }
        return result;
    }


    @Transactional(rollbackFor = Exception.class)
    @Override
    public List<HospitalMaterial> winBiddingResult(WinBiddingResultDTO dto) {
        MaterialInquiry inquiry = this.getOne(Wrappers.<MaterialInquiry>query()
                .eq("ref_id", dto.getRefId())
                .eq("hospital_id", UserUtils.getHospitalId())
        );
        if (inquiry == null) {
            throw new BusinessException("询价单不存在，请检查");
        }

        /** 修改询价单状态  flow_status已完成 */

        if (!MaterialInquiryStatus.PUBLISHED.getValue().equals(inquiry.getFlowStatus())) {
            throw new BusinessException("询价单已完成，不允许重复操作");
        }

        inquiry.setFlowStatus(MaterialInquiryStatus.FINISHED.getValue());
        super.saveOrUpdate(inquiry);

//        this.update(Wrappers.<MaterialInquiry>update()
//                .set("flow_status", MaterialInquiryStatus.FINISHED.getValue())
//                .eq("id", inquiry.getId()));

        /** 报价明细信息完善  中标价格和中标价来源 */
        List<WinBiddingResultDTO.Item> itemList = dto.getItems();
        List<MaterialInquiryItem> inquiryItems = Lists.newArrayListWithCapacity(itemList.size());
        List<MaterialBidItem> bidItems = Lists.newArrayList();
        List<HospitalMaterial> hms = Lists.newArrayList();

        for (WinBiddingResultDTO.Item item : itemList) {

            /** 询价明细信息完善  中标价格和中标价来源 */
            MaterialInquiryItem miItem = materialInquiryItemService.getOne(Wrappers.<MaterialInquiryItem>query()
                    .eq("ref_id", item.getItemRefId())
            );
            Supplier supplier = supplierService.getOne(Wrappers.<Supplier>query()
                    .eq("name", item.getSupplierName())
            );

            if (supplier == null) {
                throw new BusinessException(String.format("供应商%s不存在，请检查", item.getSupplierName()));
            }

            /** 添加医院供应商关系 */
            HospitalSupplier hs = hospitalSupplierService.getOne(Wrappers.<HospitalSupplier>query()
                    .eq("supplier_id", supplier.getId())
                    .eq("hospital_id", UserUtils.getHospitalId()));
            if (hs == null) {
                hs = new HospitalSupplier()
                        .setInactive(HospitalSupplier.ENABLE)
                        .setHospitalId(UserUtils.getHospitalId())
                        .setSupplierId(supplier.getId());
                hospitalSupplierService.save(hs);
            } else if (hs.getInactive() == HospitalSupplier.DISABLE) {
                hospitalSupplierService.update(Wrappers.<HospitalSupplier>update()
                        .set("inactive", HospitalSupplier.ENABLE)
                        .eq("id", hs.getId())
                );
            }

            /** 添加厂商信息 */
            Manufacturer manufacturer = manufacturerService.getOne(Wrappers.<Manufacturer>query()
                    .eq("supplier_id", supplier.getId())
                    .eq("name", miItem.getManufacturerName())
            );
            if (manufacturer == null) {
                manufacturer = new Manufacturer()
                        .setSupplierId(supplier.getId())
                        .setName(miItem.getManufacturerName())
                        .setPinyin(PinYinUtils.getAlpha(miItem.getManufacturerName()));
                manufacturerService.save(manufacturer);
            }


            /** 修改供应商角色 */
            userService.changeRoles(supplier.getLoginKey(), Lists.newArrayList(RoleConsts.SUPPLIER_MANAGER));

            miItem.setSkuOfficialPrice(item.getSkuOfficialPrice())
                    .setSupplierCode(item.getSupplierCode())
                    .setSupplierId(supplier.getId())
                    .setSupplierName(supplier.getName())
                    .setSkuOfficialPriceSrc(item.getSkuOfficialPriceSrc());
            inquiryItems.add(miItem);

            List<MaterialBidItem> items = materialBidItemService.list(Wrappers.<MaterialBidItem>query()
                    .eq("inquiry_item_id", miItem.getId()));
            items.stream().forEach(o ->
                    o.setSkuOfficialPrice(item.getSkuOfficialPrice()).setSkuOfficialPriceSrc(item.getSkuOfficialPriceSrc()));
            bidItems.addAll(items);

            /** todo 中标的供应商添加耗材信息，资质信息 */
            /** 添加商品 */
            /*Material material = materialService.getOne(Wrappers.<Material>query()
                    .eq("supplier_id", supplier.getId())
                    .eq("manufacturer_id", manufacturer.getId())
                    .eq("material_name", miItem.getMaterialName())
            );
            if (material == null) {
                material = new Material()
                        .setCatalogId(miItem.getCatalogId())
                        .setSupplierId(supplier.getId())
                        .setManufacturerId(manufacturer.getId())
                        .setMaterialName(miItem.getMaterialName())
                        .setMaterialTypeCode(Material.TYPE_CODE_CONSUMABLES)
                        .setPinyin(PinYinUtils.getPinYin(miItem.getMaterialName()));
                materialService.save(material);
            }*/
            Material material = new Material()
                    .setCatalogId(miItem.getCatalogId())
                    .setSupplierId(supplier.getId())
                    .setSupplierName(supplier.getName())
                    .setManufacturerId(manufacturer.getId())
                    .setManufacturerName(manufacturer.getName())
                    .setMaterialName(miItem.getMaterialName())
                    .setMaterialTypeCode(Material.TYPE_CODE_CONSUMABLES+"")
                    .setPinyin(PinYinUtils.getAlpha(miItem.getMaterialName()));
            materialService.save(material);

            /** 添加品规 */
            MaterialSpec materialSpec = materialSpecService.getOne(Wrappers.<MaterialSpec>query()
                    .eq("material_spec", miItem.getMaterialSpec())
                    .eq("material_id", material.getId()));

            if (materialSpec == null) {
                materialSpec = new MaterialSpec()
                        .setMaterialId(material.getId())
                        .setMaterialSpec(miItem.getMaterialSpec())
                        .setInputCodingType(0+"")
                        .setUnit(miItem.getSkuUnit())
                        .setPrice(miItem.getSkuOfficialPrice());
                materialSpecService.save(materialSpec);
            }

            /** 添加院内耗材 */
            HospitalMaterial hospitalMaterial = hospitalMaterialService.getOne(Wrappers.<HospitalMaterial>query()
                    .eq("material_id", material.getId())
                    .eq("material_spec_id", materialSpec.getMaterialSpec())
                    .eq("hospital_id", UserUtils.getHospitalId())
            );
            if (hospitalMaterial == null) {
                hospitalMaterial = new HospitalMaterial()
                        .setHospitalId(UserUtils.getHospitalId())
                        .setMaterialId(material.getId())
                        .setMaterialSpecId(materialSpec.getId())
                        .setMaterialSpec(materialSpec.getMaterialSpec())
                        .setMaterialCode(SerialUtils.generateCode(SerialRuleConsts.BASE_HOSPITAL_MATERIAL_CODE,
                                SerialOwnerUtils.getHospitalOwner(UserUtils.getHospitalId())))
                        .setMaterialName(material.getMaterialName())
                        .setPrice(materialSpec.getPrice())
                        .setUnit(materialSpec.getUnit())
                        .setIsConsignment(materialSpec.getIsConsignment())
                        .setIsOneThingOneYard(materialSpec.getIsOneThingOneYard())
                        .setManufacturerId(material.getManufacturerId())
                        .setManufacturerName(material.getManufacturerName())
                        .setSupplierId(supplier.getId())
                        .setSupplierName(supplier.getName())
                        .setSupplierCode(supplier.getCode())
                        .setInactive(HospitalMaterial.ACTIVATE);
                hms.add(hospitalMaterial);
            } else if (hospitalMaterial.getInactive() == HospitalMaterial.DEACTIVATE) {
                hospitalMaterial.setInactive(HospitalMaterial.ACTIVATE);
                hms.add(hospitalMaterial);
            }

        }
        materialInquiryItemService.updateBatchById(inquiryItems);
        materialBidItemService.updateBatchById(bidItems);
        if (!hms.isEmpty()) {
            hospitalMaterialService.saveOrUpdateBatch(hms);
        }


        /** 报价单修改状态  flow_status已完成 */
        materialBidService.update(Wrappers.<MaterialBid>update()
                .eq("inquiry_id", inquiry.getId())
                .set("flow_status", MaterialBidStatus.FINISHED.getValue()));

        /** todo 向所有参与报价的供应商发送询价完成提醒 */
        List<MaterialBid> list = materialBidService.list(Wrappers.<MaterialBid>query().select("supplier_code").eq("inquiry_id", inquiry.getId()));
        for (MaterialBid bid : list) {
            System.out.println(bid.getSupplierCode());
        }

        return hms;
    }


    private void saveBid(List<Supplier> supplierList, MaterialInquiry materialInquiry,
                         List<InquiryDTO.InquiryItemDTO> inquiryItems, List<MaterialInquiryItem> inquiryItemList) {
        /** 保存报价单 */
        List<MaterialBid> materialBidList = Lists.newArrayListWithCapacity(supplierList.size());
        MaterialBid materialBid;
        for (Supplier supplier : supplierList) {
            materialBid = new MaterialBid();
            materialBid.setInquiryId(materialInquiry.getId())
                    .setInquiryKey(materialInquiry.getBusKey())
                    .setInquiryDate(materialInquiry.getBusDate())
                    .setHospitalId(UserUtils.getHospitalId())
                    .setHospitalName(UserUtils.getHospital().getName())
                    .setBidStartDate(materialInquiry.getBidStartDate())
                    .setBidEndDate(materialInquiry.getBidEndDate())
                    .setSupplierId(supplier.getId())
                    .setSupplierCode(supplier.getCode())
                    .setSupplierName(supplier.getName())
                    .setFlowStatus("unsubmit")
                    .setDeptId(materialInquiry.getDeptId())
                    .setDeptName(materialInquiry.getDeptName());
            materialBidList.add(materialBid);
        }
        materialBidService.saveBatch(materialBidList);

        /** 保存报价明细 */
        List<MaterialBidItem> materialBidItemList = Lists.newArrayList();
        MaterialBidItem materialBidItem;
        Map<String, List<String>> inquiryItemMap = inquiryItems.stream()
                .collect(Collectors.toMap(o -> o.getRefId(), o -> o.getSupplierNames(), (o1, o2) -> o1));
        for (MaterialBid bid : materialBidList) {
            for (MaterialInquiryItem inquiryItem : inquiryItemList) {
                List<String> supplierName = inquiryItemMap.get(inquiryItem.getRefId()).stream()
                        .filter(o -> bid.getSupplierName().equals(o)).collect(Collectors.toList());
                if (supplierName.isEmpty()) {
                    continue;
                }
                materialBidItem = new MaterialBidItem();
                materialBidItem.setBidId(bid.getId())
                        .setBiddingStrategies("normal")
                        .setInquiryItemId(inquiryItem.getId())
                        .setCatalogIdHospital(inquiryItem.getCatalogIdHospital())
                        .setCatalogNameHospital(inquiryItem.getCatalogNameHospital())
                        .setCatalogId(inquiryItem.getCatalogId())
                        .setCatalogName(inquiryItem.getCatalogName())
                        .setMaterialName(inquiryItem.getMaterialName())
                        .setMaterialSpec(inquiryItem.getMaterialSpec())
                        .setManufacturerName(inquiryItem.getManufacturerName())
                        .setSkuUnit(inquiryItem.getSkuUnit())
                        .setDeliveryAddress(inquiryItem.getDeliveryAddress())
                        .setSkuPriceMax(inquiryItem.getSkuPriceMax())
                        .setSkuPriceMin(inquiryItem.getSkuPriceMin())
                        .setQtyYear(inquiryItem.getQtyYear())
                        .setCertificateNo(inquiryItem.getCertificateNo() != null ? inquiryItem.getCertificateNo() : null)
                        .setSunpurchaseCode(inquiryItem.getSunpurchaseCode() != null ? inquiryItem.getSunpurchaseCode() : null);
                materialBidItemList.add(materialBidItem);
            }
        }
        materialBidItemService.saveBatch(materialBidItemList);
    }

    private void saveSupplier(Map<String, List<InquiryDTO.SupplierDTO>> supplierItemMap, List<Supplier> supplierList) {


        /** 判断供应商是否存在，不存在时，创建角色账号 */
        for (String supplierName : supplierItemMap.keySet()) {
            InquiryDTO.SupplierDTO supplierItem = supplierItemMap.get(supplierName).get(0);
            /** 校验手机号 */
            Supplier supplier = supplierService.getOne(Wrappers.<Supplier>query()
                    .eq("name", supplierItem.getName())
            );

            if (supplier == null) {
                supplier = new Supplier();
                String code = SerialUtils.generateCode(SerialRuleConsts.BASE_SUPPLIER_CODE);
                supplier.setLoginKey(code)
                        .setCode(supplier.getLoginKey())
                        .setName(supplierItem.getName())
                        .setMobile(supplierItem.getMobile())
                        .setContactor(supplierItem.getContactor())
                        .setCompanyCode("default")
                        .setEmail("default")
                        .setAddress("default")
                        .setIsDrug(GlobalConsts.NO_STR)
                        .setIsReagent(GlobalConsts.NO_STR)
                        .setIsConsumable(GlobalConsts.YES_STR);

                /** 添加机构 */
                Office office = new Office();
                office.setCode(StringUtils.getRandomStr(10))
                        .setName(supplier.getName());
                if (!officeService.save(office)) {
                    throw new BusinessException("机构添加失败");
                }

                /** 添加用户，供应商编号作为主账户 */
                UserVO infoVO = new UserVO();
                infoVO.setOfficeId(office.getId())
                        .setLoginKey(supplier.getLoginKey())
                        .setNickname(supplier.getName())
                        .setEmail(supplier.getEmail())
                        .setMobile(supplier.getMobile())
                        .setRoleCodes(Lists.newArrayList(RoleConsts.SUPPLIER_TMP_BID))
                        .setRemark("供应商" + supplier.getName() + "主账号");
                User user = userService.addUser(infoVO);
                if (user == null || StringUtils.isBlank(user.getId())) {
                    throw new BusinessException("主用户添加失败");
                }

                /** 修改供应商角色 */
                userService.changeRoles(supplier.getLoginKey(), Lists.newArrayList(RoleConsts.SUPPLIER_TMP_BID));

                /** 添加供应商 */
                supplier.setOfficeId(office.getId());
                supplierService.save(supplier);
                log.info("新增供应商：{}({})", supplier.getName(), supplier.getLoginKey());
            }

            /** 添加短信发送列表 */
            supplierList.add(supplier);
        }

        /** todo 对所有供应商发送短信提醒 */
        for (Supplier supplier : supplierList) {
            System.out.println(supplier.getCode());
        }
    }

    private QueryWrapper<MaterialInquiry> getQueryWrapper(MaterialInquiryQueryRequest request) {
        return Wrappers.<MaterialInquiry>query()
                .like(StringUtils.isNotBlank(request.getBusKey()), "bus_key", request.getBusKey())
                .like(StringUtils.isNotBlank(request.getFlowStatus()), "flow_status", request.getFlowStatus())
                .orderByDesc("gmt_modified");
    }

}
